package com.huang.single;

public class SingleDemo2 {
    public volatile SingleDemo2 instance = null;

    private SingleDemo2() {

    }

    public SingleDemo2 getInstance() {

        if (null == instance) {
            synchronized (SingleDemo2.class) {
                //线程安全问题，因此需要再synchronized前后加一次空判断，DCL
                if (null == instance) {
                    instance = new SingleDemo2();
                }

            }
        }
        return instance;
    }
}
